/*
 * @Date: 2023-03-11 23:59:27
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-04-19 13:49:11
 * @Description: 基础常用工具类型
 */
import config from '@/config'
const { sysCode } = config

// localStorage存储
export const setLocalItem = (key: string, item: any): void => {
  const setItem = typeof item === 'object' ? JSON.stringify(item) : item
  localStorage.setItem(`${sysCode}_${key}`, setItem)
}

// localStorage获取
export const getLocalItem = function (key: string): any {
  const getItem = localStorage.getItem(`${sysCode}_${key}`)
  if (getItem?.indexOf('[') === 0 || getItem?.indexOf('{') === 0) {
    return JSON.parse(getItem)
  } else {
    return getItem
  }
}

// localStorage移除
export const removeLocalItem = (key: string): void => {
  localStorage.removeItem(`${sysCode}_${key}`)
}

// localStorage存储
export const setSessionItem = (key: string, item: any): void => {
  const setItem = typeof item === 'object' ? JSON.stringify(item) : item
  sessionStorage.setItem(`${sysCode}_${key}`, setItem)
}

// sessionStorage获取
export const getSessionItem = function (key: string): any {
  const getItem = sessionStorage.getItem(`${sysCode}_${key}`)
  if (getItem?.indexOf('[') === 0 || getItem?.indexOf('{') === 0) {
    return JSON.parse(getItem)
  } else {
    return getItem
  }
}

// sessionStorage移除
export const removeSessionItem = (key: string): void => {
  sessionStorage.removeItem(`${sysCode}_${key}`)
}

export const isNotEmpty = (obj: any): Boolean => {
  return !(obj === null || obj === undefined || obj === '')
}
